#ifndef HEARTBEATCONTROLLER_H
#define HEARTBEATCONTROLLER_H

#include <QObject>
#include <QTimer>
#include "FocusMachineModel.h"

class HeartbeatController : public QObject
{
    Q_OBJECT

public:
    explicit HeartbeatController(QThread *thread, QObject *parent = nullptr);

public slots:
    void initialize();
    void startConnectToModbusServer(const QString &ip, int port);
    void startDisconnectFromModbusServer();
    void startHeartbeat();
    void stopHeartbeat();

signals:
    void heartbeatMissed();
    void heartbeatDetected();
    void modbusServerConnected();
    void modbusServerDisconnected();
    void connectionStatusChanged(bool isConnected); // 新增信号

private slots:
    void checkHeartbeat();

private:

    FocusMachineModel *m_model;
    bool m_isRunning;
    void MySleep(uint32_t ms);
    bool MySleep(uint32_t ms, bool *value);
    void connectToModbusServer(const QString &ip, int port);
    void disconnectFromModbusServer();

    QThread *m_thread;
};

#endif // HEARTBEATCONTROLLER_H
